package cn.edu.just.firstjavaapp.l20;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class SumFrame extends JFrame {
    SumFrame(){
        this.setBounds(100,100,300,200);
        this.setLayout(new FlowLayout());
        JTextField textFieldNumber1 = new JTextField();
        textFieldNumber1.setColumns(10);
        this.add(textFieldNumber1);

        JTextField textFieldNumber2 = new JTextField();
        textFieldNumber2.setColumns(20);
        this.add(textFieldNumber2);

        JTextField textFieldResult = new JTextField();
        textFieldResult.setColumns(10);


        JButton button = new JButton("确定");
        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String txtNumber1 = textFieldNumber1.getText();
                String txtNumber2 = textFieldNumber2.getText();
                int sum = Integer.parseInt(txtNumber1)+Integer.parseInt(txtNumber2);
                textFieldResult.setText(sum+"");
            }
        });
        this.add(button);


        this.add(textFieldResult);
    }

    public static void main(String[] args) {
        SumFrame sumFrame = new SumFrame();
        sumFrame.setVisible(true);
    }
}
